import type { RuleProcessor } from '@react-querybuilder/core';
import { defaultRuleProcessorDrizzle } from '@react-querybuilder/core';
import type { Column, Table } from 'drizzle-orm';
import * as drizzleOperators from 'drizzle-orm';

// const negateIfNotOp = (op: string, sql: SQL) =>
//   op.startsWith('not') || op.startsWith('doesnot') ? not(sql) : sql;

/**
 * Given a Drizzle table config, returns a {@link @react-querybuilder/core!.RuleProcessor RuleProcessor}
 * for use by {@link @react-querybuilder/core!.formatQuery formatQuery}.
 *
 * It's probably unnecessary to call this function directly, but rather implicitly from the
 * {@link @react-querybuilder/core!RuleGroupProcessor RuleGroupProcessor} generated by
 * {@link generateDrizzleRuleGroupProcessor}.
 */
export const generateDrizzleRuleProcessor =
  (table: Table | Record<string, Column>): RuleProcessor =>
  (rule, options) =>
    defaultRuleProcessorDrizzle(rule, { ...options, context: { table, drizzleOperators } });
